<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学习vue</title>
    <!-- 引入vue -->
    <script src="../js/vue.js"></script>
    <style>
        *{
            margin:6px;
            padding:6px;
        }
    </style>
</head>
<body>
    <!-- 准备好一个容器，和vue绑定的代码叫vue模板 -->
    <div id="root">
        <div>啊啊{{wee}}</div>
        <button @click="wee2">change</button>
    </div>
    <script>
        //设置为 false 以阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true
            },
            computed:{
                wee(){
                    return this.isHot?'hot':"cold"
                }
            },
            methods:{
                wee2(){
                    this.isHot = !this.isHot
                }
            },
            //监视属性
            watch:{
                isHot:{
                    //当isHot被改变时调用
                    handler(newValue, oldValue){
                        console.log(this.isHot,oldValue,newValue)
                    },
                    //初始化时调用handler
                    immediate:true,
                }
            },
        })
        //监视的第二种写法
        vm.$watch('isHot', {
            //当isHot被改变时调用
            handler(newValue, oldValue){
                    console.log(this.isHot,oldValue,newValue)
            },
            //初始化时调用handler
            immediate:true,
        });
    </script>    
</body>
</html>